package chapter13;

import java.util.ArrayList;
import java.util.DoubleSummaryStatistics;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-26 上午8:42
 */
public class StreamTest2 {
    public static void main(String[] args) {
        List<Orders> orders = new ArrayList<>();
        orders.add(new Orders("test1", 23.4, 200));
        orders.add(new Orders("test2", 33.4, 260));
        orders.add(new Orders("test3", 43.4, 280));
        orders.add(new Orders("test4", 53.4, 300));
        orders.add(new Orders("test5", 63.4, 440));
        orders.stream().map(x -> x.getAmount() * x.getPrice()).forEach(System.out::println);

        double price = orders.stream().map(x -> x.getAmount() * x.getPrice()).reduce((sum, m) -> sum + m).get();
        System.out.println("Total price is " + price);

        DoubleSummaryStatistics dss = orders.stream().mapToDouble((sc) -> sc.getPrice() * sc.getAmount()).summaryStatistics();
        System.out.println("amount of goods:" + dss.getCount());
        System.out.println("total price:" + dss.getSum());
        System.out.println("average price:" + dss.getAverage());
        System.out.println("max price:" + dss.getMax());
        System.out.println("min price:" + dss.getMin());
    }
}
